<?php
include("./fckeditor/fckeditor.php");
include("../include/upload.php");
if ($_POST['webgrab'] == 'clipvn') {
	$info_url_html = xem_web($_POST['urlgrab']);
	$url_play = explode('<li><a href="', $info_url_html);
	$total_play = count($url_play);
	$total_plays = $total_play-1;

	$info_img = explode('width="216" height="306" src="', $info_url_html);
	$info_img = explode('?v=', $info_img[1]);
	$info_name = explode('<div class="title" itemprop="name"><h1>', $info_url_html);
	$info_name = explode('</h1></div>', $info_name[1]);
	$info_name_en = explode('<div class="originaltitle">', $info_url_html);
	$info_name_en = explode('</div>', $info_name_en[1]);
	$info_daodien = explode('Đạo diễn: <strong>', $info_url_html);
	$info_daodien = explode('</strong></li>', $info_daodien[1]);
	$info_dienvien = explode('Diễn viên: <strong>', $info_url_html);
	$info_dienvien = explode('</strong></li>', $info_dienvien[1]);
	$info_nam = explode('Phát hành: <strong>', $info_url_html);
	$info_nam = explode('</strong></li>', $info_nam[1]);
	$info_sx = explode('Sản xuất: <strong>', $info_url_html);
	$info_sx = explode('</strong></li>', $info_sx[1]);
	$info_time = explode('Thời lượng: <strong>', $info_url_html);
	$info_time = explode('</strong></li>', $info_time[1]);
	$info_tt = explode('<div class="filmdescription" itemprop="description">', $info_url_html);
	$info_tt = explode('</p>', $info_tt[1]);
	$info_tag	=	get_ascii($info_name[0].", ".$info_name_en[0]);
}
elseif ($_POST['webgrab'] == 'yeu79net') {
	$info_url_html = xem_web($_POST['urlgrab']);
	$url_play_phim = explode('<span class="bt_xemphim"><a href="', $info_url_html);
	$url_play_phim = explode('" title="', $url_play_phim[1]);
	$url_play_html_phim = $url_play_phim[0];
	$url_play_phim = xem_web($url_play_html_phim);
	$url_play = explode('<li class="', $url_play_phim);
	$total_play = count($url_play);
	$total_plays = $total_play-1;

	$info_name = explode('.jpg" alt="', $info_url_html);
	$info_name = explode(' - ', $info_name[1]);
	$info_name_en = explode('">', $info_name[1]);
	$info_daodien = explode('Đạo diễn:</h3>', $info_url_html);
	$info_daodien = explode('<p class="attribute"></p>', $info_daodien[1]);
	$info_dienvien = explode('Diễn viên:</h3>', $info_url_html);
	$info_dienvien = explode('<p class="attribute"></p>', $info_dienvien[1]);
	$info_nam = explode('Năm phát hành:</h3>', $info_url_html);
	$info_nam = explode('<p class="attribute"></p>', $info_nam[1]);
	$info_sx = explode('Nhà sản xuất:</h3>', $info_url_html);
	$info_sx = explode('<p class="attribute"></p>', $info_sx[1]);
	$info_time = explode('Thời lượng:</h3>', $info_url_html);
	$info_time = explode('<p class="attribute"></p>', $info_time[1]);
	$info_tt = explode('<div class="noidungphim">', $info_url_html);
	$info_tt = explode('<div class="hr"></div>', $info_tt[1]);
	$info_tag	=	get_ascii($info_name[0].", ".$info_name_en[0]);
}
elseif ($_POST['webgrab'] == 'phimphim') {
	$info_url_html = xem_web($_POST['urlgrab']);
	$url_play_phim = explode(');" href="./xem-phim', $info_url_html);
	$url_play_phim = explode('#player">', $url_play_phim[1]);
	$url_play_html_phim = 'http://phimphim.com/xem-phim'.$url_play_phim[0];
	$url_play_phim = xem_web($url_play_html_phim);
	$url_play = explode('<a href="xem-', $url_play_phim);
	$total_play = count($url_play);
	$total_plays = $total_play-1;

	$info_name = explode('<p>Tên phim:	<span>', $info_url_html);
	$info_name = explode(' - ', $info_name[1]);
	$info_name_en = explode('<p>Tên phim:	<span>', $info_url_html);
	$info_name_en = explode(' - ', $info_name_en[1]);
	$info_daodien = explode('<p>Đạo diễn: 	<span>', $info_url_html);
	$info_daodien = explode('</span></p>', $info_daodien[1]);
	$info_dienvien = explode('<p>Diễn viên: 	<span>', $info_url_html);
	$info_dienvien = explode('</span></p>', $info_dienvien[1]);
	$info_nam = explode('<p>Năm phát hành: 	<span>', $info_url_html);
	$info_nam = explode('</span></p>', $info_nam[1]);
	$info_sx = explode('<p>Sản xuất: 	<span>', $info_url_html);
	$info_sx = explode('</span></p>', $info_sx[1]);
	$info_time = explode('<p>Thời lượng: 	<span>', $info_url_html);
	$info_time = explode('</span></p>', $info_time[1]);
	$info_tt = explode('<div class="desc entry content">', $info_url_html);
	$info_tt = explode('<p class="name">Từ khóa:', $info_tt[1]);
	$info_tag	=	get_ascii($info_name[0].", ".$info_name_en[0]);
}
elseif ($_POST['webgrab'] == 'phim8') {
	$info_url_html = xem_web($_POST['urlgrab']);
	$url_play_phim = explode('<a href="http://phim8.info/xem-phim/', $info_url_html);
	$url_play_phim = explode('" alt="Xem phim trực tuyến"', $url_play_phim[1]);
	$url_play_html_phim = 'http://phim8.info/xem-phim/'.$url_play_phim[0];
	$url_play_phim = xem_web($url_play_html_phim);
	$url_play = explode('<a href="xem-', $url_play_phim);
	$total_play = count($url_play);
	$total_plays = $total_play-1;

	$info_name = explode('<dt>Tên Phim:</dt>', $info_url_html);
	$info_name = explode(' - ', $info_name[1]);
	$info_name_en = explode(' 2', $info_name[1]);
	$info_daodien = explode('<dt>Đạo diễn:</dt>', $info_url_html);
	$info_daodien = explode('</a></dd>', $info_daodien[1]);
	$info_dienvien = explode('<dt>Diễn viên:</dt>', $info_url_html);
	$info_dienvien = explode('</a></dd>', $info_dienvien[1]);
	$info_nam = explode('<dt>Năm phát hành:</dt>', $info_url_html);
	$info_nam = explode('</a></dd>', $info_nam[1]);
	$info_sx = explode('<dt>Sản xuất:</dt>', $info_url_html);
	$info_sx = explode('</dd>', $info_sx[1]);
	$info_time = explode('<dt>Thời lượng:</dt>', $info_url_html);
	$info_time = explode('</dd>', $info_time[1]);
	$info_tt = explode('NỘI DUNG PHIM</span></div>', $info_url_html);
	$info_tt = explode('<span>Tags:</span>', $info_tt[1]);
	$info_tag	=	get_ascii($info_name[0].", ".$info_name_en[0]);
}
$phimid	=	$_GET['phimid'];
if(!$phimid) {
	$phimid	=	0;
}else {
	?>
    <script type="text/javascript">$(document).ready(function () {$('#addfilm_new').hide();});</script>
    <?
}
?>
<script type="text/javascript" src="script.js"></script> 
	<div class="content_block">
		<div class="form_tbl" id="slides">	
<?php
if ((!$_POST['ok']) AND (!$_POST['submit']))  {
?>
				<span class="border_d clearfix">
<form method="post">
					<h1 style="padding: 16px 0px 16px 0px;">Thêm mới tập phim</h1>
						<div class="form_item">
							<label>Tập bắt đầu:</label>
							<input class="flat" size="30" name="episode_begin" value="1" onclick="this.select()" maxlength="250">
						</div>
						<div class="form_item">
							<label>Tập kết thúc:</label>
							<input class="flat" size="30" name="episode_end" value="<?=$total_plays?>" onclick="this.select()" maxlength="250">
						</div>
 						<div class="form_item">
							<label style="color:#777;padding-top:10px;"><span class="required_marker">*</span> Đăng 1 tập phim thì hãy điều tên tập đó vào tập kết thúc.</label>
							<span onmouseout="this.className='mb_btn1'" onmouseover="this.className='mb_btn1_hover'" class="mb_btn1">
								<button value="Submit" name="ok" type="submit">Gửi đi</button>
							</span>
						</div>
</form>
<?
}
else
{
$begin = $_POST['episode_begin'];
$end = $_POST['episode_end'];
////BEGIN CHECK EPISODE
if(!is_numeric($begin) && !is_numeric($end)){
$episode_begin = 1;
$episode_end = $total_plays;
}elseif(!is_numeric($begin) && !is_numeric($end)){
$episode_begin = 1;
$episode_end = 10;
}elseif(!is_numeric($begin)){
$episode_begin = $episode_end = $end;
}else{
$episode_begin = $begin; $episode_end = $end;
}
////END CHECK EPISODE
if (!$_POST['submit']) {
?>
					<form name="themeform" enctype="multipart/form-data" method="post">
                    <!-- thong tin bo phim -->
                    <h1 style="padding: 16px 0px 16px 0px;">Thêm tập phim vào phim có sắn</h1>
                    <div class="form_item">
							<label>Chọn phim:</label>
							<?=ipos_acp_film($phimid,1);?>
					</div>
                    
                    <div id="addfilm_new">
                        <h1 style="padding: 16px 0px 16px 0px;">Thêm phim mới</h1>
                    <div class="form_item">
                                <label>Tên bộ phim:</label>
                                <input class="flat" size="30" name="tenphim" value="<?=htmltxt($info_name[0])?>"  maxlength="250">
                        </div>
                        <div class="form_item">
                                <label>Tên tiếng anh:</label>
                                <input class="flat" size="30" name="tentienganh" value="<?=htmltxt($info_name_en[0])?>"  maxlength="250">
                        </div>
                        <div class="form_item">
								<?php if(UPLOAD_IMAGES == 1) { ?>
                                <label>Ảnh (Upload):</label>
                                <div style="float:left;">
                                <input style="height:18px; width: 320px;" value="" id="phimimg_name" type="text" readonly="readonly" /></div>
                                <div style="float:left;" class="browse"><input name="phimimg" id="phimimg" value="" type="file"></div>
                                <div style="clear:both;"></div>
								<? } else { ?>
								<label>Liên kết ảnh:</label>
                                <input class="flat" size="30" name="phimimg" value=""  maxlength="250">
								<? } ?>
                        </div>
						<script>
                        $('#phimimg').change(function(){
                            $('#phimimg_name').val($(this).val());
                        });
                        </script>
                        <div class="form_item">
                                <label>Đạo diễn:</label>
                                <input class="flat" size="30" name="daodien" value="<?=htmltxt($info_daodien[0])?>" maxlength="250">
                        </div>
                        <div class="form_item">
                                <label>Diễn viên:</label>
                                <input class="flat" size="30" name="dienvien" value="<?=htmltxt($info_dienvien[0])?>" maxlength="250">
                        </div>
                        <div class="form_item">
                                <label>Nhà sản xuất:</label>
                                <input class="flat" size="30" name="nhasanxuat" value="<?=htmltxt($info_sx[0])?>" maxlength="250">
                        </div>
                        <div class="form_item">
                                <label>Thời lượng:</label>
                                <input class="flat" size="30" name="thoiluong" value="<?=htmltxt($info_time[0])?>" maxlength="250">
                        </div>
                        <div class="form_item">
                                <label>Năm sản xuất:</label>
                                <input class="flat" size="30" name="namsanxuat" value="<?=htmltxt($info_nam[0])?>" maxlength="250">
                        </div>
                        <div class="form_item">
                                <label>Chất lượng:</label>
                                <input class="flat" size="30" name="chatluong" value="HD" maxlength="250">
                        </div>
                        <div class="form_item">
                                <label>Trainer Url:</label>
                                <input class="flat" size="30" name="trailer" value="" maxlength="250">
                        </div>
                        <div class="form_item">
                                <label>Quốc Gia:</label>
                                <?=ipod_country($quocgia);?>
                        </div>
                        <div class="form_item">
                                <label>Phân loại phim:</label>
                                <?=ipod_film_pl($phimbo);?>
                        </div>
                        <table cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td class="form_item" width="180">Thể loại:</td>
                            <td class="form_item"><?=ipos_category($theloai);?></td>
                        </tr>
                        </table>
                        <div class="form_item">
                                <label>Giới thiệu phim:</label>
                                <textarea name="phimtxt" style="width:630px; height: 130px;"><?=htmltxt($info_tt[0])?></textarea>
                        </div>
                        <div class="form_item">
                                <label>Từ khóa tìm kiếm:</label>
                                <textarea name="phimtag" style="width:630px; height: 70px;"><?=htmltxt($info_tag)?></textarea>
                        </div>
                    </div>
                   <div class="form_item">
                                <label>Server chưa phim:</label>
                               	<?=ipos_set_type();?>
                    </div>
                    <table cellpadding="0" cellspacing="0" width="100%">
                    <tr><td colspan="3"><h1 style="padding: 16px 0px 16px 0px;">Danh sách tập phim</h1></td></tr>
					<?php
                    for ($i=$episode_begin;$i<=$episode_end;$i++) {
						if ($_POST['webgrab'] == 'clipvn') {
							$play_url = explode('http://phim.clip.vn/watch/', $url_play[$i]);
							$play_url = explode('" title="', $play_url[1]);
							$name = explode('">', $url_play[$i]);
							$name = explode('</a>', $name[1]);
							$play_url = $play_url[0];
							if (!$play_url) {$play_embed[$i] = '';
							}else { $play_embed[$i] = grab('http://phim.clip.vn/watch/'.$play_url);}
						}
						elseif ($_POST['webgrab'] == 'yeu79net') {
							$play_url = explode('ing"><a href="', $url_play[$i]);
							$play_url = explode('">', $play_url[1]);
							$html_link_play = xem_web($play_url[0]);
							$link_phim = explode('proxy.link=', $html_link_play);
							$link_phim = explode('&', $link_phim[1]);
							$link_phim = $link_phim[0];
							$html_link_play_2 = xem_web($url_play_html_phim);
							$link_phim_2 = explode('proxy.link=', $html_link_play_2);
							$link_phim_2 = explode('&', $link_phim_2[1]);
							$link_phim_2 = $link_phim_2[0];
							if ($i == 1) { $play_embed[$i] = $link_phim_2;
							$name = explode('ing">', $url_play[$i]);
							$name = explode('</li>', $name[1]);
							}else {$play_embed[$i] = $link_phim;
							$name = explode('.html">', $url_play[$i]);
							$name = explode('</a>', $name[1]);
							}
						}
						elseif ($_POST['webgrab'] == 'phimphim') {
							$play_url = explode('phim-', $url_play[$i]);
							$play_url = explode('">', $play_url[1]);
							$play_url = 'http://phimphim.com/xem-phim-'.$play_url[0];
							$html_link_play = xem_web($play_url);
							$link_phim = explode('proxy.link=', $html_link_play);
							$link_phim = explode('&', $link_phim[1]);
							$link_phim = $link_phim[0];
							$html_link_play_2 = xem_web($url_play_html_phim);
							$link_phim_2 = explode('proxy.link=', $html_link_play_2);
							$link_phim_2 = explode('&', $link_phim_2[1]);
							$link_phim_2 = $link_phim_2[0];
							if ($i == 1) { $play_embed[$i] = $link_phim_2;
							$name = explode('font-weight: bold">&nbsp;', $url_play[$i]);
							$name = explode('&nbsp;</font>', $name[1]);
							}else {$play_embed[$i] = $link_phim;
							$name = explode('.html"><b>', $url_play[$i]);
							$name = explode('</b></a>', $name[1]);
							}
						}
						elseif ($_POST['webgrab'] == 'phim8') {
							$play_url = explode('phim/', $url_play[$i]);
							$play_url = explode('">', $play_url[1]);
							$play_url = 'http://phim8.info/xem-phim/'.$play_url[0];
							$html_link_play = xem_web($play_url);
							$link_phim = explode('proxy.link=', $html_link_play);
							$link_phim = explode('&', $link_phim[1]);
							$link_phim = $link_phim[0];
							$html_link_play_2 = xem_web($url_play_html_phim);
							$link_phim_2 = explode('proxy.link=', $html_link_play_2);
							$link_phim_2 = explode('&', $link_phim_2[1]);
							$link_phim_2 = $link_phim_2[0];
							if ($i == 1) { $play_embed[$i] = $link_phim_2;
							$name = explode('<font color="#00FF00">[', $url_play[$i]);
							$name = explode(']</font>', $name[1]);
							}else {$play_embed[$i] = $link_phim;
							$name = explode('.html"><b>', $url_play[$i]);
							$name = explode('</b></a>', $name[1]);
							}
						}
                    ?>
                    <tr>
                    <td class="form_item" width="12%">
                    TẬP <input onclick="this.select()" type="text" name="name[<?=$i?>]" value="<?=$name[0]?>" size="2" style="text-align:center; width: 40px;">
                    </td>
                    <td class="form_item"  width="50%">
                    <?php if (GOLD_OPEN !== '0') echo '<p class="url"><span>DEMO</span><input type="text" name="demo[<?=$i?>]" size="50"></p>';?>
                    <p class="url"><span>FULL</span><input type="text" name="url[<?=$i?>]" size="50" value="<?=$play_embed[$i]?>"></p>
                    </td>
                    <td class="form_item"  width="32%">SUB <input type="text" name="sub[<?=$i?>]" style="width:210px;"></td>
                    </tr>
                    <?php
                    }
                    ?>
                    </table>
					<div class="form_item">
							<span onmouseout="this.className='mb_btn1'" onmouseover="this.className='mb_btn1_hover'" class="mb_btn1">
                                <input type="hidden" name="episode_begin" value="<?=$episode_begin?>">
                                <input type="hidden" name="episode_end" value="<?=$episode_end?>">
                                <input type="hidden" name="ok" value="SUBMIT">
								<button value="Submit" name="submit" type="submit">Gửi đi</button>
							</span>
						</div>
					</form>
<?php
}
else {	
	$film 			=	 htmlchars(stripslashes(trim(urldecode($_POST['film']))));
	$tenphim 		= 	htmlchars(stripslashes(trim(urldecode($_POST['tenphim']))));
	$tentienganh 	= 	htmlchars(stripslashes(trim(urldecode($_POST['tentienganh']))));
	$daodien		=	htmlchars(stripslashes(trim(urldecode($_POST['daodien']))));
	$dienvien		=	htmlchars(stripslashes(trim(urldecode($_POST['dienvien']))));
	$theloai		=	','.(implode(',',$_POST['theloai'])).',';
	$quocgia		=	htmlchars(stripslashes(trim(urldecode($_POST['quocgia']))));
	$thoiluong		=	htmlchars(stripslashes(trim(urldecode($_POST['thoiluong']))));
	$nhasanxuat		=	htmlchars(stripslashes(trim(urldecode($_POST['nhasanxuat']))));
	$namsanxuat		=	htmlchars(stripslashes(trim(urldecode($_POST['namsanxuat']))));
	$phimbo			=	htmlchars(stripslashes(trim(urldecode($_POST['phimbo']))));
	$chatluong		=	htmlchars(stripslashes(trim(urldecode($_POST['chatluong']))));
	$trailer		=	htmlchars(stripslashes(trim(urldecode($_POST['trailer']))));
	$server			=	htmlchars(stripslashes(trim(urldecode($_POST['server']))));
	$phimtxt 		= 	htmlchars(stripslashes(trim(urldecode($_POST['phimtxt']))));
	$phimtag 		= 	htmlchars(stripslashes(trim(urldecode($_POST['phimtag']))));
	
	$timkiem		= 	install_tags($tenphim.','.$tentienganh.','.$daodien.','.$dienvien.','.$nhasanxuat);
	
	if(UPLOAD_IMAGES == 1) {
		$upload	=	ipupload("phimimg","film",replace($tenphim));
		if($upload) {
			$phimimg = $upload;
		}
	} else {
		$phimimg 		= 	htmlchars(stripslashes(trim(urldecode($_POST['phimimg']))));
	}
	if ($tenphim) {
		// kiếm tra phim
		$check	=	$db->database("phimid","film","tenphim = '$tenphim'");
		if($check) {
			$film	=	$check[0][0];	
		}else {
			$db->dbinstall("film","tenphim,tentienganh,daodien,dienvien,theloai,quocgia,thoiluong,nhasanxuat,namsanxuat,phimimg,phimbo,chatluong,trailer,phimtime,poster","'$tenphim','$tentienganh','$daodien','$dienvien','$theloai','$quocgia','$thoiluong','$nhasanxuat','$namsanxuat','$phimimg','$phimbo','$chatluong','$trailer','".NOW."','".$_SESSION['adminid']."'");
			$film = mysql_insert_id();
			$db->dbinstall("film_info","phimid,phimtxt,phimtag,timkiem","'$film','$phimtxt','$phimtag','$timkiem'");
		}
	}
    for ($i=$episode_begin;$i<=$episode_end;$i++){
		$t_url 		= 	$_POST['url'][$i];
		$t_demo		= 	$_POST['demo'][$i];
		$t_name 	= 	$_POST['name'][$i];
		$t_sub		= 	$_POST['sub'][$i];
		
		if ($t_url && $t_name) {
			//update dữ liệu mới
			$db->dbinstall("ep","epname,epurl,phimid,epsub,server,epdemo","'$t_name','$t_url','$film','$t_sub','$server','$t_demo'");
			header("Location: index.php?ipos=film");
		}
	}
	// báo lỗi
  }
}
?>
				</span>

			</div>
		</div>